package com.cy.pj.arithmetic.controller;

import com.cy.pj.arithmetic.service.ArithmeticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ArithmeticController {
   @ExceptionHandler(ArithmeticException.class)
   @ResponseBody
    public String doHandleArithmeticException(ArithmeticException e){
        return "The exception msg is"+e.getMessage();
    }

    @ResponseBody
    @RequestMapping("/doCompute/{n1}/{n2}")
    public String doCompute(@PathVariable Integer n1,@PathVariable Integer n2){
//       try {
           Integer result=n1/n2;
           return "The Result is  "+result;
//       }catch (ArithmeticException e){
//          e.printStackTrace();
//          return "计算工程中出现了异常，异常信息为 "+e.getMessage();
//       }

    }

    @Autowired
    private ArithmeticService arithmeticService;

   @ResponseBody
   @RequestMapping("doSum/{a}/{b}")
   public String doSun(@PathVariable Integer a,@PathVariable Integer b){
       return "求和结果为"+arithmeticService.sum(a,b);
   }
}
